import java.util.*;
import java.text.*;

class Alarm{
	int day, month, year, hour, minute;

	Alarm(int day, int month, int year, int hour, int minute){
		this.day = day;
		this.month = month;
		this.year = year;
		this.hour = hour;
		this.minute = minute;
	}
}

class AlarmLogic implements Runnable{
	ArrayList<Alarm> alarmlist = new ArrayList<Alarm>();

	void AddAlarm(Alarm a){
		alarmlist.add(a);
	}

	void MonitorAlarmsAsync(){
		Thread t = new Thread(this);
		t.start();
	}

	public void run(){
		DateFormat datef = new SimpleDateFormat("dd/MM/yyyy");
		DateFormat timef = new SimpleDateFormat("HH:mm:ss");
		try{	
		while(true){
			Date date = new Date();
			String currdate[] = (datef.format(date)).split("/");
			String currtime[] = (timef.format(date)).split(":");
			for(int i=0; i<alarmlist.size();i++){
				if(this.checkAlarmList(i, currdate, currtime)){
					alarmlist.remove(i);
					System.out.println("Alarm Ring!!");
				//	UserInteraction.PrintAlert("Alarm Ring!!");
					continue;
				}
			}
			Thread.sleep((60 - Integer.parseInt(currtime[2])) * 1000);
		}
		}catch(Exception e){
			System.out.println("Exception found: " + e);
		}
	}

	boolean checkAlarmList(int index, String currdate[], String currtime[]){
		boolean ans = false;
		if(alarmlist.get(index).day == Integer.parseInt(currdate[0]) &&
		   alarmlist.get(index).month == Integer.parseInt(currdate[1]) &&
		   alarmlist.get(index).year == Integer.parseInt(currdate[2]) &&
		   alarmlist.get(index).hour == Integer.parseInt(currtime[0]) &&
		   alarmlist.get(index).minute == Integer.parseInt(currtime[1])){
							ans = true;
						}
		return(ans);
	}
	
}

class UserInteraction{

	AlarmLogic alogic = new AlarmLogic();

	void start(){
		alogic.MonitorAlarmsAsync();
		while(true) {
			Scanner scan = new Scanner(System.in);
			System.out.print("Enter day: ");
			int day = scan.nextInt();
			System.out.print("Enter month: ");
			int month = scan.nextInt();
			System.out.print("Enter year: ");
			int year = scan.nextInt();
			System.out.print("Enter hours: ");
			int hour = scan.nextInt();
			System.out.print("Enter minutes: ");
			int minute = scan.nextInt();

			Alarm a = new Alarm(day, month, year, hour, minute);
			alogic.AddAlarm(a);
			System.out.println("\nAlarm added successfully!\n");
		}
	}

	public static void PrintAlert(String str[]){
		System.out.println(str);
	}
}


class AlarmMain{
	public static void main(String args[]){
		UserInteraction ui = new UserInteraction();
		ui.start();
	}
}